package com.study.sfd.prescription.controller;

import com.study.common.entity.PrescriptionEntity;
import com.study.common.utils.PageResult;
import com.study.common.utils.R;
import com.study.common.utils.Result;
import com.study.common.vo.PrescriptionVo;
import com.study.sfd.prescription.service.PrescriptionService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;



/**
 * prescription(处方)
 *
 * @author 王个球
 * @email wangdajunzy@163.com
 * @date 2021-11-12 13:48:21
 */
@RestController
@RequestMapping("prescription/prescription")
public class PrescriptionController
{
    @Resource
    private PrescriptionService prescriptionService;

    /**
     * 保存
     */
    @PostMapping
    public Result<?> save(@RequestBody PrescriptionEntity prescription)
    {
        int prescriptionId = prescriptionService.savePrescription(prescription);

        return Result.success(prescriptionId);
    }

    /**
     * 医生查询药品列表
     */
    @RequestMapping("/listMedicines")
    public Result<PageResult> listMedicines(@RequestParam Map<String, Object> params)
    {
        return prescriptionService.listMedicines(params);
    }

    /**
     * 列表
     */
    @GetMapping
    public Result<PageResult> list(@RequestParam Map<String, Object> params){
        PageResult page = prescriptionService.queryPage(params);

        return Result.success(page);
    }

    /**
     * 信息
     */
    @GetMapping("/{id}")
    public Result<PrescriptionVo> info(@PathVariable Integer id)
    {
		PrescriptionVo prescription = prescriptionService.info(id);
        return Result.success(prescription);
    }

    /**
     * 支付
     */
    @PostMapping("/pay/{id}")
    public Result<?> pay(@PathVariable Integer id){
        prescriptionService.pay(id);

        return Result.success();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody PrescriptionEntity prescription){
		prescriptionService.updateById(prescription);

        return R.ok();
    }
}
